package com.znz.domain;

import org.hibernate.Query;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: duyuxin
 * Date: 15-5-12
 * Time: 下午10:48
 * To change this template use File | Settings | File Templates.
 */
@RooJavaBean
@RooToString
@RooJpaActiveRecord(versionField="",identifierColumn = "id", identifierField = "id",table = "t_order_hospital_project")
public class TorderHospitalProject {

      @ManyToOne
      @JoinColumn(name="order_id")
      private  Torder torder;

      @Column(name="order_no")
      private String orderNo;

      @ManyToOne
      @JoinColumn(name="hospital_project_id")
      private ThospitalProjectAgreement thospitalProjectAgreement;

      @Column(name="hospital_name")
      private String hospitalName;

      @Column(name="project_name")
      private String projectName;

      @ManyToOne
      @JoinColumn(name="c_user_id")
      private Tcustomer tcustomer;

      @ManyToOne
      @JoinColumn(name="h_user_id")
      private Person person;

      @Column(name="state")
      private int state;

      @Column(name = "expect_cost_min")
      private double expectCostMin;

      @Column(name="expect_cost_max")
      private double expectCostMax;

      @Column(name = "cost")
      private double cost;

      @Column(name="remark")
      private String remark;

      @Column(name="expire_date")
      private Date expireDate;

      @Column(name="surgery_date")
      private Date surgeryDate;

      @Column(name = "create_date")
      private Date createDate;

      @Column(name = "update_date")
      private Date updateDate;

      public static List<TorderHospitalProject> getTorderHospitalProjectByOrderId(Long torderId){
             StringBuilder strSql=new StringBuilder();
             strSql.append("SELECT o FROM TorderHospitalProject o where o.torder.id=? ");
             TypedQuery<TorderHospitalProject> query=entityManager().createQuery(strSql.toString(),TorderHospitalProject.class);
             query.setParameter(1,torderId);
             return query.getResultList();
      }
}
